﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ServerManager.Data;
using ServerManager.Models;

namespace ServerManager.Controllers
{
    public class HomeController : Controller
    {
        private readonly ApplicationDbContext _mysqlContext;
        private readonly SqliteDbContext _sqliteContext;

        public HomeController(ApplicationDbContext mysqlContext,
            SqliteDbContext sqliteContext)
        {
            _mysqlContext = mysqlContext;
            _sqliteContext = sqliteContext;
        }

        public IActionResult Index()
        {
            //var server0 = _mysqlContext.Servers;
            //var server1 = _sqliteContext.Servers;
            //foreach (var item in server1)
            //{
            //    _mysqlContext.Servers.Add(item);
            //}
            //_mysqlContext.SaveChanges();

            //var ip0 = _mysqlContext.IpAddresses;
            //var ip1 = _sqliteContext.IpAddresses;
            //foreach (var item in ip1)
            //{
            //    _mysqlContext.IpAddresses.Add(item);
            //}
            //_mysqlContext.SaveChanges();


            //var apps0 = _mysqlContext.Apps;
            //var apps1 = _sqliteContext.Apps;
            //foreach (var item in apps1)
            //{
            //    _mysqlContext.Apps.Add(item);
            //}
            //_mysqlContext.SaveChanges();

            //return View();
            return RedirectToAction(nameof(Index), "Server");
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
